﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace IslandInterloper.Engine
{
    internal class Ship:GameClient
    {
        private string name;
        public string Name { get { return name; } }

        private double sailingDifficulty;
        public double SailingDifficulty { get { return sailingDifficulty; } }

        private double maximumSpeed;
        public double MaximumSpeed { get { return maximumSpeed; } }

        private double maximumTonnage;
        public double MaximumTonnage { get { return maximumTonnage; } }

        private int avatarChance;
        public int AvatarChance { get { return avatarChance; } }

        internal Ship(Game theGame, XElement element)
            : base(theGame)
        {
            FromXElement(element);
        }
        public void FromXElement(XElement element)
        {
            name = element.Element(GameXNames.name).Value;
            sailingDifficulty = Utilities.XElementToDouble(element.Element(GameXNames.sailingDifficulty));
            maximumSpeed = Utilities.XElementToDouble(element.Element(GameXNames.maximumSpeed));
            maximumTonnage = Utilities.XElementToDouble(element.Element(GameXNames.maximumTonnage));
            avatarChance = Utilities.XElementToInt(element.Element(GameXNames.avatarChance));
        }
        public override XElement ToXElement(XName xName)
        {
            XElement result = new XElement(xName,
                new XElement(GameXNames.name, name),
                new XElement(GameXNames.sailingDifficulty, sailingDifficulty.ToString()),
                new XElement(GameXNames.maximumSpeed, maximumSpeed.ToString()),
                new XElement(GameXNames.maximumTonnage, maximumTonnage.ToString()),
                new XElement(GameXNames.avatarChance, avatarChance.ToString())
                );
            return result;
        }
    }
}
